package edu.hnu.userserver.controller;



import edu.hnu.commonutils.Result;
import edu.hnu.commonutils.model.User;
import edu.hnu.userserver.auth.JwtOperator;
import edu.hnu.userserver.service.impl.AdminsServiceImpl;
import io.jsonwebtoken.Claims;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
//@CrossOrigin(origins = "*")
@RequestMapping("/admin")

public class AdminsController {
    @Autowired
    AdminsServiceImpl adminsService;
    @Autowired
    JwtOperator jwtOperator;
    private User parseToken(String token){
        Claims claims = jwtOperator.getClaimsFromToken(token);
        User user = new User(-1L,-2,false);
        try {
            Long id = Long.parseLong(claims.get("id").toString());
            int userType= Integer.parseInt(claims.get("user_type").toString());
            if (userType != -1) {
                // 判断是否是不是管理员
                user.setAuthorized(false);
            }else {
                user.setUserType(userType);
                user.setId(id);
                user.setAuthorized(true);
            }
        } catch (NumberFormatException e) {
            user.setAuthorized(false);
            return user;
        }
        return user;
    }
    @GetMapping("/getAllAdmin")
    @ApiOperation(value = "查看所有的管理员",notes = "查看所有的管理员，貌似没啥用的接口")
    public Result getAllAdmin(){
        System.out.println("这是controller");
        return  adminsService.getAllAdmin();
    }

}
